//**************************************************************.DA*
//   .HEADER [ KFXConfig.h ]
//--------------------------------------------------------------.D1-
//   .FILE [ KFXConfig.h ]
//   .GROUP [ KEFEX user files]
//   .AUTHOR [ Stangl ]
//--------------------------------------------------------------.F1-
//   .DESCRIPTION
//   Contains definitions of the KEFEX buffers.
//   The size definitions can be changed by the user.
//--------------------------------------------------------------
//   .HISTORY
//    Date      Author      Commentary
//   10.03.05   AST         created
//**************************************************************.DE*

#ifndef H_KFX_CONFIG
#define H_KFX_CONFIG

#ifdef __cplusplus
extern "C" {
#endif

#include "kfx_target_config_public.h"

//number of TX and RX message buffers ...
#define KFX_NW_BUFSIZE  1   //must be <= 255
//number of possible ECRRs
#define KFX_MAX_ECRRS   1   //must be <= 255
//number of possible TCRRs
#define KFX_MAX_TCRRS   1   //must be <= 255

#if KFX_NW_BUFSIZE > 255
   Error
#endif
#if KFX_MAX_ECRRS > 255
   Error
#endif
#if KFX_MAX_TCRRS > 255
   Error
#endif

//------------------------------ Structs -----------------------------------
typedef struct
{
   uint8 u8_TargetAddress;
   uint8 u8_Service;
   uint8 au8_Data[7];
} T_KFXNWFIFOEntry;

typedef struct
{
   uint8 u8_WriteIndex;
   uint8 u8_ReadIndex;
   uint8 u8_NumEntries;
   uint8 u8_Overrun;
   T_KFXNWFIFOEntry at_KFXQueue[KFX_NW_BUFSIZE];  //must be placed at the end to be able to have flexible length ...
} T_KFXNWFIFO;

typedef union
{
   uint32 u32;
   uint16 u16[2];
   uint8 u8[4];
   sint8 s8[4];
   sint32 s32;
   sint16 s16[2];
}
U_ldw;

typedef struct
{
   //configuration:
   uint8  u8_Active;
   uint16 u16_VariableIndex;
   uint16 u16_MaxWaitTime;
   uint32 u32_UpperHysteresis;
   uint32 u32_LowerHysteresis;

   //actual values:
   uint32 u32_NextSendTime;
   uint32 u32_LastSendValue;
   U_ldw u_LowMark;
   U_ldw u_HighMark;
} T_ECRR;

typedef struct
{
   //configuration:
   uint8  u8_Active;
   uint8  u8_TimeStamped;
   uint16 u16_VariableIndex;
   uint16 u16_Interval;

   //actual values:
   uint32 u32_NextSendTime;
   uint32 u32_BaseTime; //base time for time stamps
} T_TCRR;

//------------------------------ Globals -----------------------------------
extern volatile const uint16 gu16_KFXNWBufsize;
extern volatile const uint16 gu16_KFXMaxNumECRRs;
extern volatile const uint16 gu16_KFXMaxNumTCRRs;

extern KFX_TRG_HUGE T_KFXNWFIFO gt_KFXNWTXFIFO;
extern KFX_TRG_HUGE T_KFXNWFIFO gt_KFXNWRXFIFO;

extern KFX_TRG_HUGE T_ECRR gat_KFXECRRs[KFX_MAX_ECRRS];
extern KFX_TRG_HUGE T_TCRR gat_KFXTCRRs[KFX_MAX_TCRRS];

#ifdef __cplusplus
}
#endif


#endif
